package com.shop.manager.controller;

//import com.shop.manager.entity.PayLog;
//import com.shop.manager.http.HttpResult;
//import com.shop.manager.http.PageResult;
import com.base.common.entity.PayLog;
import com.base.common.http.HttpResult;
import com.base.common.http.PageResult;
import com.shop.manager.service.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 支付日志增删改查
 */
@RestController
@RequestMapping("/payLog")
public class PayLogController {

    /**
     * @Description 注入service对象
     */
    @Autowired
    private PayLogService payLogService;

    /**
     * @Description 添加支付日志
     * @param payLog 支付日志对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public HttpResult add(@RequestBody(required = false) PayLog payLog){
        try {
            payLogService.add(payLog);
            return HttpResult.ok("添加支付日志成功!");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return HttpResult.error("添加支付日志失败!");
    }

    /**
     * @Description 批量删除支付日志
     * @param ids 支付日志id的数组
     * @return
     */
    @RequestMapping("/delete")
    public HttpResult delete(@RequestBody String[] ids){
        try {
            payLogService.deleteByIds(ids);
            //删除成功
            return HttpResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //删除异常
            return HttpResult.error();
        }
    }

    /**
     * @Description 修改支付日志
     * @param payLog 修改的支付日志对象
     * @return
     */
    @RequestMapping("/update")
    public HttpResult update(@RequestBody(required = false) PayLog payLog){
        try {
            payLogService.update(payLog);
            return HttpResult.ok("修改支付日志成功!");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return HttpResult.error("修改支付日志失败!");
    }

    /**
     * @Description 根据ID查询支付日志
     * @param id 支付日志id
     * @return
     */
    @RequestMapping("/getById")
    public HttpResult getById(@RequestParam String id){
        return HttpResult.ok(payLogService.findOne(id));
    }

    /**
     * @Description 条件分页查询
     * @param pageNum 当前页码
     * @param size 当前页条数
     * @param payLog 查询条件对象
     * @return
     */
    @RequestMapping("/getAll")
    public HttpResult getAll(@RequestParam("pageNum") Integer pageNum, @RequestParam("size") Integer size, @RequestBody(required = false) PayLog payLog){
        try {
            //分页查询
            PageResult result = payLogService.findPage(pageNum, size, payLog);
            //查询成功
            return HttpResult.ok(result);
        } catch (Exception e) {
            e.printStackTrace();
            //查询异常
            return HttpResult.error("查询支付日志异常");
        }
    }
}
